﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class notice_notice : System.Web.UI.Page
{
    DataClassesDataContext db1 = new DataClassesDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack == true)
        {
            GridView2.DataSourceID = "";
            var notice = (from c in db1.proc_GetAcessNotic()
                          select c).ToList();
            GridView2.DataSource = notice;
            GridView2.DataBind();
            int type = Convert.ToInt32(Session["type"].ToString());
            if (type == 0)
            {
                Button1.Visible = false;
            }
            else
            {
                Button1.Visible = true;
            }
            string IP = Request.ServerVariables.Get("Remote_Addr").ToString();
            string nowtime = DateTime.Now.ToString();
            DateTime nowtime1 = Convert.ToDateTime(nowtime);
            int nowusername = Convert.ToInt32(Session["username"]);
            var newrizhi = new rizhi
            {
                userName = nowusername,
                time = nowtime1,
                ip = IP,
                caozuo = "进入通知公告"
            };
            db1.rizhi.InsertOnSubmit(newrizhi);
            db1.SubmitChanges();

        }
    }
    protected void GridView2_RowDataBound1(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lbl = (Label)e.Row.Cells[0].FindControl("Label3");
            lbl.Text = (GridView2.PageIndex * GridView2.PageSize + e.Row.RowIndex + 1).ToString();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("add_notice.aspx");
    }
}